'use strict';

const Controller = require('egg').Controller;

class TaskController extends Controller {
    async index() {

    }

    //获取任务列表
    async list() {
        const { ctx } = this;
        let params = ctx.request.query;

        //params.status = 'pending';
        let tree = await ctx.service.task.getListAndChild(params);
        ctx.body = JSON.stringify({code:0, data:tree});

    }


    //获取任务列表
    async taskTree() {
        const { ctx } = this;
        let params = ctx.request.query;

        let tree = await ctx.service.task.getTaskTree(params);
        ctx.body = JSON.stringify({code:0, data:tree});

    }

    //创建任务
    async create(){
        const { ctx } = this;
        
        let params = ctx.request.body;

        let task = await ctx.service.task.save(params);

        ctx.body = JSON.stringify({code:0, data:task});
    }


    //完成任务
    async finish(){
        const { ctx } = this;
        
        let params = ctx.request.body;

        let task = await ctx.service.task.save({id: params.id, status: 10});

        ctx.body = JSON.stringify({code:0, data:task});
    }

    //删除任务
    async del(){
        const { ctx } = this;
        
        let params = ctx.request.body;

        let task = await ctx.service.task.del(params.id);

        ctx.body = JSON.stringify({code:0, data:task});
    }

    async info() {
        const { ctx } = this;
        
        let params = ctx.request.query;
        
        let info = await ctx.service.task.info(params.id);

        ctx.body = JSON.stringify(info);
    }
}

module.exports = TaskController;
